import { tasksList } from "$api/tasks"
import { newgetDataGrid } from "$utils/table"
import dayjs from "dayjs"

export default {
  data() {
    return {

      dataGrid: {
        // 1 加载中 2 加载完成有数据 3 加载完成没有数据
        loading: 1,
        data: [],
        pagination: {
          // 每页数量
          pageSize: 1000,
          // 当前页数
          pageNum: 1,
          // 总页数
          sumPageNum: ""
        },
      },
      time: null
    }
  },
  beforeDestory() {
    clearInterval(this.time)
  },
  methods: {
    async search(form, flag) {
      const params = {
        taskDate: dayjs().subtract(0, "day").format("YYYY-MM-DD")
      }

      await newgetDataGrid(this.dataGrid, tasksList, params, false, data => {
        this.dataGrid.data = data.filter(v => v.status !== 9)
        this.dataGrid.data = this.dataGrid.data.map(item => {
          const { remark } = item
          const { selectBg, selctColor } = remark ? JSON.parse(remark) : {}
          return {
            ...item,
            selctColor,
            selectBg,
            surplus: 0,
            surplusFlag: true
          }
        })

        for (const item of this.dataGrid.data) {
          if (item.status === 5) {
            const { surplus, status } = this.surplusTime(item)
            item.surplus = surplus
            item.surplusFlag = status
            this.time = setInterval(() => {
              const { surplus, status } = this.surplusTime(item)
              item.surplus = surplus
              item.surplusFlag = status
            }, 1000);
          }
        }
      })
    },
    clickRow(item, content) {
      const { START, END } = this.basicFlag
      const { text } = content
      if (text === "开始") {
        this.openDialog(item, START)
      } else if (text === "结束") {
        this.openDialog(item, END)
      }
    }
  }

}
